/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.sql.Timestamp;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;   
import javax.persistence.CascadeType;
import javax.persistence.OneToOne;

/**
 *
 * @author Ee Ting
 */
@Entity
public class ProdRecordSOP implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long prodRecordSOPId;
    
    private int month;
    private int year;
    @OneToOne(cascade = {CascadeType.PERSIST})  
    private Product prod;
    private int sopFigure;
    private double prodPercent;
    @OneToOne(cascade = {CascadeType.PERSIST})  
    private SystemUser createdBy;
    private Timestamp createdDate;
    
    public void create(int mth, int yr, Product prod, int sFig, double pPercent, SystemUser user)
    {
        this.setMonth(mth);
        this.setYear(yr);
        this.setProd(prod);
        this.setSopFigure(sFig);
        this.setProdPercent(pPercent);
        this.setCreatedBy(user);
        java.util.Date tmp = new java.util.Date();
        this.setCreatedDate(new Timestamp(tmp.getTime()));
    }
    
    public SystemUser getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(SystemUser createdBy) {
        this.createdBy = createdBy;
    }

    public Timestamp getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Timestamp createdDate) {
        this.createdDate = createdDate;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public Product getProd() {
        return prod;
    }

    public void setProd(Product prod) {
        this.prod = prod;
    }

    public double getProdPercent() {
        return prodPercent;
    }

    public void setProdPercent(double prodPercent) {
        this.prodPercent = prodPercent;
    }

    public int getSopFigure() {
        return sopFigure;
    }

    public void setSopFigure(int sopFigure) {
        this.sopFigure = sopFigure;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public Long getProdRecordSOPId() {
        return prodRecordSOPId;
    }

    public void setProdRecordSOPId(Long id) {
        this.prodRecordSOPId = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (prodRecordSOPId != null ? prodRecordSOPId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ProdRecordSOP)) {
            return false;
        }
        ProdRecordSOP other = (ProdRecordSOP) object;
        if ((this.prodRecordSOPId == null && other.prodRecordSOPId != null) || (this.prodRecordSOPId != null && !this.prodRecordSOPId.equals(other.prodRecordSOPId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.ProdRecordSOP[ id=" + prodRecordSOPId + " ]";
    }
    
}
